﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Common;
using System.Linq;
using System.Text;
using Microsoft.Practices.EnterpriseLibrary.Data;

namespace PegasCompany.Data
{
    public class PageData
    {
        public static int GetRecordCount(int contentType, int iYear, int iMonth)
        {
            Database db = DatabaseFactory.CreateDatabase();
            const string sqlCommand = "[dbo].gspSiteContent_GetCount";
            using (DbCommand dbCommand = db.GetStoredProcCommand(sqlCommand, contentType, iYear, iMonth))
            {
                using (DataSet ds = db.ExecuteDataSet(dbCommand))
                {
                    if (ds == null || ds.Tables[0].Rows.Count == 0) throw new ApplicationException("Could not get record count");
                    ds.Tables[0].TableName = "RecordCount";

                    DataRow dr = ds.Tables[0].Rows[0];
                    return dr["RecordCount"] != DBNull.Value ? Convert.ToInt32(dr["RecordCount"]) : 1;
                }
            }
        }
    }
}
